package io.jpress.module.article.flowable.delegate;

import com.jfinal.aop.Inject;
import io.jpress.core.flowable.AutoLoadServiceTaskDelegate;
import io.jpress.module.article.model.ArticleFlowStatus;
import io.jpress.module.article.service.ArticleFlowStatusService;
import io.jpress.module.article.service.ArticleService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.JavaDelegate;

@AutoLoadServiceTaskDelegate(title = "允许文章被重新编辑", type = "article", order = 3)
public class NeedModefyArticleDelegate implements JavaDelegate {


    @Inject
    private ArticleService articleService;

    @Inject
    private ArticleFlowStatusService articleFlowStatusService;


    @Override
    public void execute(DelegateExecution execution) {

        ArticleFlowStatus flowStatus = articleFlowStatusService.findByProcessInstanceId(execution.getProcessInstanceId());
        if (flowStatus != null && !flowStatus.isFinished()) {
            flowStatus.setStatus(ArticleFlowStatus.STATUS_REBUT);
            articleFlowStatusService.update(flowStatus);
        }

    }
}
